package com.pactera.asmp.server.common.constants;

import com.pactera.asmp.server.common.utils.FastJsonUtil;

/**
 * @ProjectName: asmpserver
 * @Package: com.pactera.asmp.server.common.constants
 * @ClassName: Result
 * @Author: lvzhiqiang
 * @Description:
 * @Date: 2019/8/27 15:50
 * @Version: 1.0
 */
public class Result<T> {
    private int code;
    private String message;
    private T data;

    private Result() {
    }

    public Result(ResultCode resultCode) {
        this.code = resultCode.code();
        this.message = resultCode.message();
    }

    public Result(ResultCode resultCode, T data) {
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.data = data;
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(String message) {
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Result SUCCESS() {
        return new Result(ResultCode.SUCCESS);
    }

    public static <T> Result SUCCESS(T data) {
        return new Result(ResultCode.SUCCESS, data);
    }

    public static Result FAIL() {
        return new Result(ResultCode.FAIL);
    }

    public static Result FAIL(String message) {
        return new Result(ResultCode.FAIL,message);
    }

    @Override
    public String toString() {
        return FastJsonUtil.BeanToJson(this);
    }

}